package com.ww.yaodao.util;

import com.alibaba.druid.filter.config.ConfigTools;
import com.alibaba.druid.util.DruidPasswordCallback;
import com.alibaba.druid.util.StringUtils;
import lombok.extern.slf4j.Slf4j;

import java.util.Properties;

@Slf4j
public class CallBackPassword extends DruidPasswordCallback {
    //    公钥
    static final String PUBLIC_KEY = "MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAKOftzR/d" +
            "rJtRioF9tTCrV6eCtPkQ87KYXKqL6W1+rBU+UBDHmC4ELkm5aN/pdArPMjO0qLdoiOa24XZP3XIVcsCAwEAAQ==";

    @Override
    public void setProperties(Properties properties) {
        super.setProperties(properties);
        //获取配置文件中的已经加密的密码
        String pwd = (String) properties.get("password");
        if (!StringUtils.isEmpty(pwd)) {
            try {
                // 将密码进行解密
                String password = ConfigTools.decrypt(PUBLIC_KEY, pwd);
                setPassword(password.toCharArray());
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
}
